Python/Unit Tests/CheatSheet
- I inevitably look up the same syntax again and again while writing unit tests.
- Snippets:
# Parent classes unittest.TestCase unittest.IsolatedAsyncioTestCase # Assertions assertEqual(), assertNotEqual() # assertEquals is deprecated assertTrue(), assertFalse() assertAlmostEqual(), assertNotAlmostEqual() assertRaises(), assertRaisesRegex() assertRegex(), assertNotRegex() # Mocks from unittest.mock import ( mock, Mock, AsyncMock, MagicMack, patch, create_autospec ) ## Auto specs: create_autospec
call
objects are weird tuples that have special rules for equality